# -*- coding: utf-8 -*-
import functools
import time

import numpy as np
from naoqi import qi
from naoqi import ALBroker
import cv2

class Hough():
    def __init__(self):
        self.ses = qi.Session()
        self.ses.connect("tcp://192.168.43.115:9559")
        self.myBroker = ALBroker("myBroker",
                                 "0.0.0.0",  # listen to anyone
                                 0,  # find a free port and use it
                                 "192.168.43.115",  # parent broker IP
                                 9559)  # parent broker port
        # self.video = self.ses.service("ALVideoDevice")
        self.mem = self.ses.service("ALMemory")
        self.red=self.ses.service("ALRedBallDetection")
        self.red.subscribe("RedBallDetection", 1000, 0.0)
        self.redball=self.mem.subscriber("redBallDetected")

        self.con_redball=self.redball.signal.connect(functools.partial(self.Redball_Det,"redBallDetected"))
    def Redball_Det(self,event,value):
        print event,value
        print "检测到红球。"
hough=Hough()
while True:

    data=hough.mem.getData("redBallDetected")
    time.sleep(1)
    print data